using System;
using GameFramework.Sound;
using UnityEngine;
using Unity.VisualScripting;
using UnityGameFramework.Runtime;
using PlaySoundUpdateEventArgs = UnityGameFramework.Runtime.PlaySoundUpdateEventArgs;

namespace LS.UGFUnits
{
    [UnitShortTitle("Play Sound")]
    [UnitSurtitle("Update")]
    public sealed class PlaySoundUpdate : FrameworkEventUnit<PlaySoundUpdateEventArgs>
    {
        protected override int EventId => PlaySoundUpdateEventArgs.EventId;
        protected override string HookName => UGFHookNames.PlaySoundUpdate;

        [DoNotSerialize]
        [PortLabelHidden]
        public ValueOutput SerialId
        {
            get;
            private set;
        }

        [DoNotSerialize]
        [PortLabelHidden]
        public ValueOutput SoundAssetName
        {
            get;
            private set;
        }

        [DoNotSerialize]
        [PortLabelHidden]
        public ValueOutput SoundGroupName
        {
            get;
            private set;
        }

        [DoNotSerialize]
        [PortLabelHidden]
        public ValueOutput PlaySoundParams
        {
            get;
            private set;
        }

        [DoNotSerialize]
        [PortLabelHidden]
        public ValueOutput Progress
        {
            get;
            private set;
        }

        [DoNotSerialize]
        [PortLabelHidden]
        public ValueOutput BindingEntity
        {
            get;
            private set;
        }

        [DoNotSerialize]
        [PortLabelHidden]
        public ValueOutput UserData { get; private set; }

        protected override void Definition()
        {
            base.Definition();
            SerialId = ValueOutput<int>(nameof(SerialId));
            SoundAssetName = ValueOutput<string>(nameof(SoundAssetName));
            SoundGroupName = ValueOutput<string>(nameof(SoundGroupName));
            PlaySoundParams = ValueOutput<PlaySoundParams>(nameof(PlaySoundParams));
            Progress = ValueOutput<float>(nameof(Progress));
            BindingEntity = ValueOutput<Entity>(nameof(BindingEntity));
            UserData = ValueOutput<object>(nameof(UserData));
        }

        protected override void AssignArguments(Flow flow, PlaySoundUpdateEventArgs args)
        {
            base.AssignArguments(flow, args);
            flow.SetValue(SerialId, args.SerialId);
            flow.SetValue(SoundAssetName, args.SoundAssetName);
            flow.SetValue(SoundGroupName, args.SoundGroupName);
            flow.SetValue(PlaySoundParams, args.PlaySoundParams);
            flow.SetValue(Progress, args.Progress);
            flow.SetValue(BindingEntity, args.BindingEntity);
            flow.SetValue(UserData, args.UserData);
        }
    }
}